"""
__slots__魔法 限制对象只能绑定某些属性

Version: 0.1
Author: yuwl
Date：2024-3-26
"""

class Person(object):

    # 限定Person对象只能绑定_name、_age、_gender
    __slots__ = ('_name', '_age', '_gender')

    def __init__(self, name, age):
        self._name = name
        self._age = age

    # getter方法
    @property
    def name(self):
        return self._name
    
    # setter方法
    @name.setter
    def name(self, name):
        self._name = name

    @property
    def age(self):
        return self._age
    
    @age.setter
    def age(self, age):
        self._age = age

    def play(self):
        if self._age <= 16:
            print('%s正在玩飞行棋。' % self._name)
        else:
            print('%s正在玩斗地主。' % self._name) 

if __name__ == '__main__':
    person = Person('张三', 22)
    person.play()
    person._gender = 15
    # AttributeError: 'Person' object has no attribute '_birth'
    person._birth = '20240326'